package org.example.y24.m11;

import java.util.Scanner;

public class MontyGoBang {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] board = new int[n][m];
        scanner.nextLine();
        for (int i = 0; i < n; i++) {
            String line = scanner.nextLine();
            for (int j = 0; j < m; j++) {
                if (line.charAt(j) == '1') {
                    board[i][j] = 1;
                } else if (line.charAt(j) == '2') {
                    board[i][j] = 2;
                }
            }
        }
        int score1 = calculateScore(board, 1);
        int score2 = calculateScore(board, 2);
        System.out.println(score1 + " " + score2);
    }

    private static int calculateScore(int[][] board, int player) {
        int score = 0;
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j <= board[0].length - 5; j++) {
                boolean hasFiveInARow = true;
                for (int k = j; k < j + 5; k++) {
                    if (board[i][k] != player) {
                        hasFiveInARow = false;
                        break;
                    }
                }
                if (hasFiveInARow) {
                    score++;
                }
            }
        }
        for (int j = 0; j < board[0].length; j++) {
            for (int i = 0; i <= board.length - 5; i++) {
                boolean hasFiveInAColumn = true;
                for (int k = i; k < i + 5; k++) {
                    if (board[k][j] != player) {
                        hasFiveInAColumn = false;
                        break;
                    }
                }
                if (hasFiveInAColumn) {
                    score++;
                }
            }
        }
        for (int i = 0; i <= board.length - 5; i++) {
            for (int j = 0; j <= board[0].length - 5; j++) {
                boolean hasFiveDiagonal = true;
                for (int k = 0; k < 5; k++) {
                    if (board[i + k][j + k] != player) {
                        hasFiveDiagonal = false;
                        break;
                    }
                }
                if (hasFiveDiagonal) {
                    score++;
                }
            }
        }
        for (int i = 4; i < board.length; i++) {
            for (int j = 0; j <= board[0].length - 5; j++) {
                boolean hasFiveReverseDiagonal = true;
                for (int k = 0; k < 5; k++) {
                    if (board[i - k][j + k] != player) {
                        hasFiveReverseDiagonal = false;
                        break;
                    }
                }
                if (hasFiveReverseDiagonal) {
                    score++;
                }
            }
        }

        return score;
    }
}
